import java.util.Arrays;

public class SolutionInterview16_16 {
    public int[] subSort(int[] array) {
        if (array.length==0){
            return new int[]{-1,-1};
        }
        int[] max=new int[array.length];
        max[0]=array[0];
        for (int i=1;i<array.length;i++){
            max[i]=Math.max(max[i-1],array[i]);
        }
        int[] min=new int[array.length];
        min[array.length-1]=array[array.length-1];
        for (int i=array.length-2;i>=0;i--){
            min[i]=Math.min(min[i+1],array[i]);
        }
        int l=-1;
        for (int i=0;i<array.length-1;i++){
            int j=i;
            while (j+1<array.length && array[j]==array[j+1]){
                j++;
            }
            if (j==array.length-1){
                break;
            }
            if (array[i]>min[j+1]){
                l=i;
                break;
            }else if (array[i]==min[j+1]){
                l=j+1;
                break;
            }
            i=j;
        }
        int r=-1;
        for (int i=array.length-1;i>0;i--){
            int j=i;
            while (j-1>=0 && array[j]==array[j-1]){
                j--;
            }
            if (j==0){
                break;
            }
            if (array[i]<max[j-1]){
                r=i;
                break;
            }else if (array[i]==max[j-1]){
                r=j-1;
            }
            i=j;
        }
        return new int[]{l,r};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionInterview16_16().subSort(new int[]{1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, 18, 19})));
    }
}
